﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Threading.Tasks;
using Net.Chirash.Twitter.TwitterClient;
using Net.Chirash.Twitter.TweetZone.WindowComponents.MiniControls;
using Net.Chirash.Twitter.TweetZone.WindowComponents.ViewModels;
using Net.Chirash.Twitter.TwitterDatabase;

namespace Net.Chirash.Twitter.TweetZone.WindowComponents.Containers
{
    /// <summary>
    /// UsersContainer.xaml の相互作用ロジック
    /// </summary>
    public partial class UsersContainer : Container
    {
        #region Constructors

        public UsersContainer(UserContainerViewModel viewmodel)
            : base(viewmodel)
        {
            InitializeComponent();
        }

        public UsersContainer()
            : this(new UserContainerViewModel(UserListType.Friend, App.CurrentApp.User))
        {
        }

        public UsersContainer(UserListType type, User user)
            : this(new UserContainerViewModel(type, user))
        {
        }

        #endregion

        #region Private Methods

        private void UsersListBox_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (e.VerticalChange > 0.0)
            {
                double remains = e.ExtentHeight - (e.ViewportHeight + e.VerticalOffset);
                if (0.0 <= remains && remains <= 1.0)
                {
                    (ViewModel as UserContainerViewModel).PagingStart();
                }
            }

        }

        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            var usersContainerVM = this.ViewModel as UserContainerViewModel;
            var user = (sender as FrameworkElement).DataContext as User;
            if (usersContainerVM.OpenUserProfileWindow.CanExecute(user))
                usersContainerVM.OpenUserProfileWindow.Execute(user);
        }

        #endregion

    }
}
